<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   Python 数据分析入门  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://dataunion.org/19488.html",
                  host: "http://dataunion.org",
                  prePath: "http://dataunion.org",
                  scheme: "http",
                  pathBase: "http://dataunion.org/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466457281: Accept with keywords: (title(0.4):Python,数据分析,社区,入门,数盟, topn(0.533333333333):社区,人工智能,数盟,深度学习,行业资讯,R语言,数组,数据挖掘,数据分析,自定义,Python,假设,均值,职业规划,可视化,文章,基础架构,数据,属性,稻谷,函数,python,假设检验,检验,库中,编程语言,代码,p值,浮点,模块).-->
 </head>
 <body onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    Python 数据分析入门
   </h1>
  </div>
  <div class="container" id="xmain">
   ﻿﻿
   <title>
    Python 数据分析入门 | 数盟社区
   </title>
   <!-- All in One SEO Pack 2.2.7.6.2 by Michael Torbert of Semper Fi Web Design[32,60] -->
   <!-- /all in one seo pack -->
   <!--
<div align="center">
<a href="http://strata.oreilly.com.cn/hadoop-big-data-cn?cmp=mp-data-confreg-home-stcn16_dataunion_pc" target="_blank"><img src="http://dataunion.org/wp-content/uploads/2016/05/stratabj.jpg"/ ></a>
</div>
-->
   <header id="header-web">
    <div class="header-main">
     <hgroup class="logo">
      <h1>
       <a href="http://dataunion.org/" rel="home" title="数盟社区">
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/logo.png"/>
       </a>
      </h1>
     </hgroup>
     <!--logo-->
     <nav class="header-nav">
      <ul class="menu" id="menu-%e4%b8%bb%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-71" id="menu-item-71">
        <a href="http://dataunion.org/category/events" title="events">
         活动
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22457" id="menu-item-22457">
          <a href="http://dataunion.org/2016timeline">
           2016档期
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22459" id="menu-item-22459">
          <a href="http://dataunion.org/category/parterc">
           合作会议
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-has-children menu-item-20869" id="menu-item-20869">
        <a href="http://dataunion.org/category/tech" title="articles">
         文章
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20867" id="menu-item-20867">
          <a href="http://dataunion.org/category/tech/base" title="base">
           基础架构
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3302" id="menu-item-3302">
          <a href="http://dataunion.org/category/tech/ai" title="ai">
           人工智能
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3303" id="menu-item-3303">
          <a href="http://dataunion.org/category/tech/analysis" title="analysis">
           数据分析
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21920" id="menu-item-21920">
          <a href="http://dataunion.org/category/tech/dm">
           数据挖掘
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3314" id="menu-item-3314">
          <a href="http://dataunion.org/category/tech/viz" title="viz">
           可视化
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3305" id="menu-item-3305">
          <a href="http://dataunion.org/category/tech/devl" title="devl">
           编程语言
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-20876" id="menu-item-20876">
        <a href="http://dataunion.org/category/industry">
         行业
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16328" id="menu-item-16328">
          <a href="http://dataunion.org/category/industry/case" title="case">
           行业应用
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2112" id="menu-item-2112">
          <a href="http://dataunion.org/category/industry/demo" title="demo">
           Demo展示
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21562" id="menu-item-21562">
          <a href="http://dataunion.org/category/industry/news">
           行业资讯
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-311" id="menu-item-311">
        <a href="http://dataunion.org/category/sources" title="sources">
         资源
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20870" id="menu-item-20870">
        <a href="http://dataunion.org/category/books" title="book">
         图书
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21363" id="menu-item-21363">
        <a href="http://dataunion.org/category/training">
         课程
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-21853" id="menu-item-21853">
        <a href="http://dataunion.org/category/jobs">
         职位
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22050" id="menu-item-22050">
          <a href="http://dataunion.org/category/career">
           职业规划
          </a>
         </li>
        </ul>
       </li>
      </ul>
     </nav>
     <!--header-nav-->
    </div>
   </header>
   <!--header-web-->
   <div id="main">
    <div id="soutab">
     <form action="http://dataunion.org/" class="search" method="get">
     </form>
    </div>
    <div id="container">
     <nav id="mbx">
      当前位置：
      <a href="http://dataunion.org">
       首页
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech">
       文章
      </a>
      &gt;  正文
     </nav>
     <!--mbx-->
     <article class="content">
      <header align="centre" class="contenttitle">
       <div class="mscc">
        <h1 class="mscctitle">
         <a href="http://dataunion.org/19488.html">
          Python 数据分析入门
         </a>
        </h1>
        <address class="msccaddress ">
         <em>
          1,972 次阅读 -
         </em>
         <a href="http://dataunion.org/category/tech" rel="category tag">
          文章
         </a>
        </address>
       </div>
      </header>
      <div class="content-text">
       <p>
        出处：
        <a href="http://python.jobbole.com/81133/">
         伯乐在线
        </a>
       </p>
       <p>
        最近，
        <a href="http://alstatr.blogspot.com/" target="_blank">
         Analysis with Programming
        </a>
        加入了
        <a href="http://planetpython.org/" target="_blank">
         Planet Python
        </a>
        。作为该网站的首批特约博客，我这里来分享一下如何通过Python来开始数据分析。具体内容如下：
       </p>
       <ol>
        <li>
         数据导入
         <ul>
          <li>
           导入本地的或者web端的CSV文件；
          </li>
         </ul>
        </li>
        <li>
         数据变换；
        </li>
        <li>
         数据统计描述；
        </li>
        <li>
         假设检验
         <ul>
          <li>
           单样本t检验；
          </li>
         </ul>
        </li>
        <li>
         可视化；
        </li>
        <li>
         创建自定义函数。
        </li>
       </ol>
       <h3>
        数据导入
       </h3>
       <p>
        这是很关键的一步，为了后续的分析我们首先需要导入数据。通常来说，数据是CSV格式，就算不是，至少也可以转换成CSV格式。在Python中，我们的操作如下：
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python keyword">
          import
         </code>
         <code class="python plain">
          pandas as pd
         </code>
        </div>
        <div class="line number2 index1 alt1">
        </div>
        <div class="line number3 index2 alt2">
         <code class="python comments">
          # Reading data locally
         </code>
        </div>
        <div class="line number4 index3 alt1">
         <code class="python plain">
          df
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          pd.read_csv(
         </code>
         <code class="python string">
          '/Users/al-ahmadgaidasaad/Documents/d.csv'
         </code>
         <code class="python plain">
          )
         </code>
        </div>
        <div class="line number5 index4 alt2">
        </div>
        <div class="line number6 index5 alt1">
         <code class="python comments">
          # Reading data from web
         </code>
        </div>
        <div class="line number7 index6 alt2">
         <code class="python plain">
          data_url
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python string">
          "https://raw.githubusercontent.com/alstat/Analysis-with-Programming/master/2014/Python/Numerical-Descriptions-of-the-Data/data.csv"
         </code>
        </div>
        <div class="line number8 index7 alt1">
         <code class="python plain">
          df
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          pd.read_csv(data_url)
         </code>
        </div>
       </blockquote>
       <p>
        为了读取本地CSV文件，我们需要pandas这个数据分析库中的相应模块。其中的read_csv函数能够读取本地和web数据。
       </p>
       <h3>
        数据变换
       </h3>
       <p>
        既然在工作空间有了数据，接下来就是数据变换。统计学家和科学家们通常会在这一步移除分析中的非必要数据。我们先看看数据：
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python comments">
          # Head of the data
         </code>
        </div>
        <div class="line number2 index1 alt1">
         <code class="python functions">
          print
         </code>
         <code class="python plain">
          df.head()
         </code>
        </div>
        <div class="line number3 index2 alt2">
        </div>
        <div class="line number4 index3 alt1">
         <code class="python comments">
          # OUTPUT
         </code>
        </div>
        <div class="line number5 index4 alt2">
         <code class="python spaces">
         </code>
         <code class="python plain">
          Abra  Apayao  Benguet  Ifugao  Kalinga
         </code>
        </div>
        <div class="line number6 index5 alt1">
         <code class="python value">
          0
         </code>
         <code class="python value">
          1243
         </code>
         <code class="python value">
          2934
         </code>
         <code class="python value">
          148
         </code>
         <code class="python value">
          3300
         </code>
         <code class="python value">
          10553
         </code>
        </div>
        <div class="line number7 index6 alt2">
         <code class="python value">
          1
         </code>
         <code class="python value">
          4158
         </code>
         <code class="python value">
          9235
         </code>
         <code class="python value">
          4287
         </code>
         <code class="python value">
          8063
         </code>
         <code class="python value">
          35257
         </code>
        </div>
        <div class="line number8 index7 alt1">
         <code class="python value">
          2
         </code>
         <code class="python value">
          1787
         </code>
         <code class="python value">
          1922
         </code>
         <code class="python value">
          1955
         </code>
         <code class="python value">
          1074
         </code>
         <code class="python value">
          4544
         </code>
        </div>
        <div class="line number9 index8 alt2">
         <code class="python value">
          3
         </code>
         <code class="python value">
          17152
         </code>
         <code class="python value">
          14501
         </code>
         <code class="python value">
          3536
         </code>
         <code class="python value">
          19607
         </code>
         <code class="python value">
          31687
         </code>
        </div>
        <div class="line number10 index9 alt1">
         <code class="python value">
          4
         </code>
         <code class="python value">
          1266
         </code>
         <code class="python value">
          2385
         </code>
         <code class="python value">
          2530
         </code>
         <code class="python value">
          3315
         </code>
         <code class="python value">
          8520
         </code>
        </div>
        <div class="line number11 index10 alt2">
        </div>
        <div class="line number12 index11 alt1">
         <code class="python comments">
          # Tail of the data
         </code>
        </div>
        <div class="line number13 index12 alt2">
         <code class="python functions">
          print
         </code>
         <code class="python plain">
          df.tail()
         </code>
        </div>
        <div class="line number14 index13 alt1">
        </div>
        <div class="line number15 index14 alt2">
         <code class="python comments">
          # OUTPUT
         </code>
        </div>
        <div class="line number16 index15 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          Abra  Apayao  Benguet  Ifugao  Kalinga
         </code>
        </div>
        <div class="line number17 index16 alt2">
         <code class="python value">
          74
         </code>
         <code class="python value">
          2505
         </code>
         <code class="python value">
          20878
         </code>
         <code class="python value">
          3519
         </code>
         <code class="python value">
          19737
         </code>
         <code class="python value">
          16513
         </code>
        </div>
        <div class="line number18 index17 alt1">
         <code class="python value">
          75
         </code>
         <code class="python value">
          60303
         </code>
         <code class="python value">
          40065
         </code>
         <code class="python value">
          7062
         </code>
         <code class="python value">
          19422
         </code>
         <code class="python value">
          61808
         </code>
        </div>
        <div class="line number19 index18 alt2">
         <code class="python value">
          76
         </code>
         <code class="python value">
          6311
         </code>
         <code class="python value">
          6756
         </code>
         <code class="python value">
          3561
         </code>
         <code class="python value">
          15910
         </code>
         <code class="python value">
          23349
         </code>
        </div>
        <div class="line number20 index19 alt1">
         <code class="python value">
          77
         </code>
         <code class="python value">
          13345
         </code>
         <code class="python value">
          38902
         </code>
         <code class="python value">
          2583
         </code>
         <code class="python value">
          11096
         </code>
         <code class="python value">
          68663
         </code>
        </div>
        <div class="line number21 index20 alt2">
         <code class="python value">
          78
         </code>
         <code class="python value">
          2623
         </code>
         <code class="python value">
          18264
         </code>
         <code class="python value">
          3745
         </code>
         <code class="python value">
          16787
         </code>
         <code class="python value">
          16900
         </code>
        </div>
       </blockquote>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_680277">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
            </td>
            <td class="code">
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        对R语言程序员来说，上述操作等价于通过print(head(df))来打印数据的前6行，以及通过print(tail(df))来打印数据的后6行。当然Python中，默认打印是5行，而R则是6行。因此R的代码head(df, n = 10)，在Python中就是df.head(n = 10)，打印数据尾部也是同样道理。
       </p>
       <p>
        在R语言中，数据列和行的名字通过colnames和rownames来分别进行提取。在Python中，我们则使用columns和index属性来提取，如下：
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python comments">
          # Extracting column names
         </code>
        </div>
        <div class="line number2 index1 alt1">
         <code class="python functions">
          print
         </code>
         <code class="python plain">
          df.columns
         </code>
        </div>
        <div class="line number3 index2 alt2">
        </div>
        <div class="line number4 index3 alt1">
         <code class="python comments">
          # OUTPUT
         </code>
        </div>
        <div class="line number5 index4 alt2">
         <code class="python plain">
          Index([u
         </code>
         <code class="python string">
          'Abra'
         </code>
         <code class="python plain">
          , u
         </code>
         <code class="python string">
          'Apayao'
         </code>
         <code class="python plain">
          , u
         </code>
         <code class="python string">
          'Benguet'
         </code>
         <code class="python plain">
          , u
         </code>
         <code class="python string">
          'Ifugao'
         </code>
         <code class="python plain">
          , u
         </code>
         <code class="python string">
          'Kalinga'
         </code>
         <code class="python plain">
          ], dtype
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python string">
          'object'
         </code>
         <code class="python plain">
          )
         </code>
        </div>
        <div class="line number6 index5 alt1">
        </div>
        <div class="line number7 index6 alt2">
         <code class="python comments">
          # Extracting row names or the index
         </code>
        </div>
        <div class="line number8 index7 alt1">
         <code class="python functions">
          print
         </code>
         <code class="python plain">
          df.index
         </code>
        </div>
        <div class="line number9 index8 alt2">
        </div>
        <div class="line number10 index9 alt1">
         <code class="python comments">
          # OUTPUT
         </code>
        </div>
        <div class="line number11 index10 alt2">
         <code class="python plain">
          Int64Index([
         </code>
         <code class="python value">
          0
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          1
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          2
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          3
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          4
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          5
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          6
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          7
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          8
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          9
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          10
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          11
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          12
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          13
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          14
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          15
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          16
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          17
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          18
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          19
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          20
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          21
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          22
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          23
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          24
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          25
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          26
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          27
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          28
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          29
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          30
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          31
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          32
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          33
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          34
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          35
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          36
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          37
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          38
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          39
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          40
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          41
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          42
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          43
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          44
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          45
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          46
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          47
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          48
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          49
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          50
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          51
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          52
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          53
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          54
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          55
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          56
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          57
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          58
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          59
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          60
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          61
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          62
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          63
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          64
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          65
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          66
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          67
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          68
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          69
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          70
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          71
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          72
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          73
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          74
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          75
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          76
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          77
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          78
         </code>
         <code class="python plain">
          ], dtype
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python string">
          'int64'
         </code>
         <code class="python plain">
          )
         </code>
        </div>
       </blockquote>
       <p>
       </p>
       <div>
       </div>
       <p>
        数据转置使用T方法，
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python comments">
          # Transpose data
         </code>
        </div>
        <div class="line number2 index1 alt1">
         <code class="python functions">
          print
         </code>
         <code class="python plain">
          df.T
         </code>
        </div>
        <div class="line number3 index2 alt2">
        </div>
        <div class="line number4 index3 alt1">
         <code class="python comments">
          # OUTPUT
         </code>
        </div>
        <div class="line number5 index4 alt2">
         <code class="python spaces">
         </code>
         <code class="python value">
          0
         </code>
         <code class="python value">
          1
         </code>
         <code class="python value">
          2
         </code>
         <code class="python value">
          3
         </code>
         <code class="python value">
          4
         </code>
         <code class="python value">
          5
         </code>
         <code class="python value">
          6
         </code>
         <code class="python value">
          7
         </code>
         <code class="python value">
          8
         </code>
         <code class="python value">
          9
         </code>
        </div>
        <div class="line number6 index5 alt1">
         <code class="python plain">
          Abra
         </code>
         <code class="python value">
          1243
         </code>
         <code class="python value">
          4158
         </code>
         <code class="python value">
          1787
         </code>
         <code class="python value">
          17152
         </code>
         <code class="python value">
          1266
         </code>
         <code class="python value">
          5576
         </code>
         <code class="python value">
          927
         </code>
         <code class="python value">
          21540
         </code>
         <code class="python value">
          1039
         </code>
         <code class="python value">
          5424
         </code>
        </div>
        <div class="line number7 index6 alt2">
         <code class="python plain">
          Apayao
         </code>
         <code class="python value">
          2934
         </code>
         <code class="python value">
          9235
         </code>
         <code class="python value">
          1922
         </code>
         <code class="python value">
          14501
         </code>
         <code class="python value">
          2385
         </code>
         <code class="python value">
          7452
         </code>
         <code class="python value">
          1099
         </code>
         <code class="python value">
          17038
         </code>
         <code class="python value">
          1382
         </code>
         <code class="python value">
          10588
         </code>
        </div>
        <div class="line number8 index7 alt1">
         <code class="python plain">
          Benguet
         </code>
         <code class="python value">
          148
         </code>
         <code class="python value">
          4287
         </code>
         <code class="python value">
          1955
         </code>
         <code class="python value">
          3536
         </code>
         <code class="python value">
          2530
         </code>
         <code class="python value">
          771
         </code>
         <code class="python value">
          2796
         </code>
         <code class="python value">
          2463
         </code>
         <code class="python value">
          2592
         </code>
         <code class="python value">
          1064
         </code>
        </div>
        <div class="line number9 index8 alt2">
         <code class="python plain">
          Ifugao
         </code>
         <code class="python value">
          3300
         </code>
         <code class="python value">
          8063
         </code>
         <code class="python value">
          1074
         </code>
         <code class="python value">
          19607
         </code>
         <code class="python value">
          3315
         </code>
         <code class="python value">
          13134
         </code>
         <code class="python value">
          5134
         </code>
         <code class="python value">
          14226
         </code>
         <code class="python value">
          6842
         </code>
         <code class="python value">
          13828
         </code>
        </div>
        <div class="line number10 index9 alt1">
         <code class="python plain">
          Kalinga
         </code>
         <code class="python value">
          10553
         </code>
         <code class="python value">
          35257
         </code>
         <code class="python value">
          4544
         </code>
         <code class="python value">
          31687
         </code>
         <code class="python value">
          8520
         </code>
         <code class="python value">
          28252
         </code>
         <code class="python value">
          3106
         </code>
         <code class="python value">
          36238
         </code>
         <code class="python value">
          4973
         </code>
         <code class="python value">
          40140
         </code>
        </div>
        <div class="line number11 index10 alt2">
        </div>
        <div class="line number12 index11 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          ...
         </code>
         <code class="python value">
          69
         </code>
         <code class="python value">
          70
         </code>
         <code class="python value">
          71
         </code>
         <code class="python value">
          72
         </code>
         <code class="python value">
          73
         </code>
         <code class="python value">
          74
         </code>
         <code class="python value">
          75
         </code>
         <code class="python value">
          76
         </code>
         <code class="python value">
          77
         </code>
        </div>
        <div class="line number13 index12 alt2">
         <code class="python plain">
          Abra     ...
         </code>
         <code class="python value">
          12763
         </code>
         <code class="python value">
          2470
         </code>
         <code class="python value">
          59094
         </code>
         <code class="python value">
          6209
         </code>
         <code class="python value">
          13316
         </code>
         <code class="python value">
          2505
         </code>
         <code class="python value">
          60303
         </code>
         <code class="python value">
          6311
         </code>
         <code class="python value">
          13345
         </code>
        </div>
        <div class="line number14 index13 alt1">
         <code class="python plain">
          Apayao   ...
         </code>
         <code class="python value">
          37625
         </code>
         <code class="python value">
          19532
         </code>
         <code class="python value">
          35126
         </code>
         <code class="python value">
          6335
         </code>
         <code class="python value">
          38613
         </code>
         <code class="python value">
          20878
         </code>
         <code class="python value">
          40065
         </code>
         <code class="python value">
          6756
         </code>
         <code class="python value">
          38902
         </code>
        </div>
        <div class="line number15 index14 alt2">
         <code class="python plain">
          Benguet  ...
         </code>
         <code class="python value">
          2354
         </code>
         <code class="python value">
          4045
         </code>
         <code class="python value">
          5987
         </code>
         <code class="python value">
          3530
         </code>
         <code class="python value">
          2585
         </code>
         <code class="python value">
          3519
         </code>
         <code class="python value">
          7062
         </code>
         <code class="python value">
          3561
         </code>
         <code class="python value">
          2583
         </code>
        </div>
        <div class="line number16 index15 alt1">
         <code class="python plain">
          Ifugao   ...
         </code>
         <code class="python value">
          9838
         </code>
         <code class="python value">
          17125
         </code>
         <code class="python value">
          18940
         </code>
         <code class="python value">
          15560
         </code>
         <code class="python value">
          7746
         </code>
         <code class="python value">
          19737
         </code>
         <code class="python value">
          19422
         </code>
         <code class="python value">
          15910
         </code>
         <code class="python value">
          11096
         </code>
        </div>
        <div class="line number17 index16 alt2">
         <code class="python plain">
          Kalinga  ...
         </code>
         <code class="python value">
          65782
         </code>
         <code class="python value">
          15279
         </code>
         <code class="python value">
          52437
         </code>
         <code class="python value">
          24385
         </code>
         <code class="python value">
          66148
         </code>
         <code class="python value">
          16513
         </code>
         <code class="python value">
          61808
         </code>
         <code class="python value">
          23349
         </code>
         <code class="python value">
          68663
         </code>
        </div>
        <div class="line number18 index17 alt1">
        </div>
        <div class="line number19 index18 alt2">
         <code class="python spaces">
         </code>
         <code class="python value">
          78
         </code>
        </div>
        <div class="line number20 index19 alt1">
         <code class="python plain">
          Abra
         </code>
         <code class="python value">
          2623
         </code>
        </div>
        <div class="line number21 index20 alt2">
         <code class="python plain">
          Apayao
         </code>
         <code class="python value">
          18264
         </code>
        </div>
        <div class="line number22 index21 alt1">
         <code class="python plain">
          Benguet
         </code>
         <code class="python value">
          3745
         </code>
        </div>
        <div class="line number23 index22 alt2">
         <code class="python plain">
          Ifugao
         </code>
         <code class="python value">
          16787
         </code>
        </div>
        <div class="line number24 index23 alt1">
         <code class="python plain">
          Kalinga
         </code>
         <code class="python value">
          16900
         </code>
        </div>
        <div class="line number25 index24 alt2">
        </div>
        <div class="line number26 index25 alt1">
         <code class="python plain">
          Other transformations such as sort can be done using &lt;code&gt;sort&lt;
         </code>
         <code class="python keyword">
          /
         </code>
         <code class="python plain">
          code&gt; attribute. Now let's extract a specific column. In Python, we do it using either &lt;code&gt;iloc&lt;
         </code>
         <code class="python keyword">
          /
         </code>
         <code class="python plain">
          code&gt;
         </code>
         <code class="python keyword">
          or
         </code>
         <code class="python plain">
          &lt;code&gt;ix&lt;
         </code>
         <code class="python keyword">
          /
         </code>
         <code class="python plain">
          code&gt; attributes, but &lt;code&gt;ix&lt;
         </code>
         <code class="python keyword">
          /
         </code>
         <code class="python plain">
          code&gt;
         </code>
         <code class="python keyword">
          is
         </code>
         <code class="python plain">
          more robust
         </code>
         <code class="python keyword">
          and
         </code>
         <code class="python plain">
          thus I prefer it. Assuming we want the head of the first column of the data, we have
         </code>
        </div>
       </blockquote>
       <p>
       </p>
       <div>
       </div>
       <p>
        其他变换，例如排序就是用sort属性。现在我们提取特定的某列数据。Python中，可以使用iloc或者ix属性。但是我更喜欢用ix，因为它更稳定一些。假设我们需数据第一列的前5行，我们有：
       </p>
       <div class="line number1 index0 alt2">
        <code class="python keyword">
         print
        </code>
        <code class="python plain">
         df.ix[:,
        </code>
        <code class="python value">
         0
        </code>
        <code class="python plain">
         ].head()
        </code>
       </div>
       <div class="line number2 index1 alt1">
       </div>
       <div class="line number3 index2 alt2">
        <code class="python comments">
         # OUTPUT
        </code>
       </div>
       <div class="line number4 index3 alt1">
        <code class="python value">
         0
        </code>
        <code class="python value">
         1243
        </code>
       </div>
       <div class="line number5 index4 alt2">
        <code class="python value">
         1
        </code>
        <code class="python value">
         4158
        </code>
       </div>
       <div class="line number6 index5 alt1">
        <code class="python value">
         2
        </code>
        <code class="python value">
         1787
        </code>
       </div>
       <div class="line number7 index6 alt2">
        <code class="python value">
         3
        </code>
        <code class="python value">
         17152
        </code>
       </div>
       <div class="line number8 index7 alt1">
        <code class="python value">
         4
        </code>
        <code class="python value">
         1266
        </code>
       </div>
       <div class="line number9 index8 alt2">
        <code class="python plain">
         Name: Abra, dtype: int64
        </code>
       </div>
       <div class="line number9 index8 alt2">
       </div>
       <div>
       </div>
       <p>
        顺便提一下，Python的索引是从0开始而非1。为了取出从11到20行的前3列数据，我们有：
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python keyword">
          print
         </code>
         <code class="python plain">
          df.ix[
         </code>
         <code class="python value">
          10
         </code>
         <code class="python plain">
          :
         </code>
         <code class="python value">
          20
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          0
         </code>
         <code class="python plain">
          :
         </code>
         <code class="python value">
          3
         </code>
         <code class="python plain">
          ]
         </code>
        </div>
        <div class="line number2 index1 alt1">
        </div>
        <div class="line number3 index2 alt2">
         <code class="python comments">
          # OUTPUT
         </code>
        </div>
        <div class="line number4 index3 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          Abra  Apayao  Benguet
         </code>
        </div>
        <div class="line number5 index4 alt2">
         <code class="python value">
          10
         </code>
         <code class="python value">
          981
         </code>
         <code class="python value">
          1311
         </code>
         <code class="python value">
          2560
         </code>
        </div>
        <div class="line number6 index5 alt1">
         <code class="python value">
          11
         </code>
         <code class="python value">
          27366
         </code>
         <code class="python value">
          15093
         </code>
         <code class="python value">
          3039
         </code>
        </div>
        <div class="line number7 index6 alt2">
         <code class="python value">
          12
         </code>
         <code class="python value">
          1100
         </code>
         <code class="python value">
          1701
         </code>
         <code class="python value">
          2382
         </code>
        </div>
        <div class="line number8 index7 alt1">
         <code class="python value">
          13
         </code>
         <code class="python value">
          7212
         </code>
         <code class="python value">
          11001
         </code>
         <code class="python value">
          1088
         </code>
        </div>
        <div class="line number9 index8 alt2">
         <code class="python value">
          14
         </code>
         <code class="python value">
          1048
         </code>
         <code class="python value">
          1427
         </code>
         <code class="python value">
          2847
         </code>
        </div>
        <div class="line number10 index9 alt1">
         <code class="python value">
          15
         </code>
         <code class="python value">
          25679
         </code>
         <code class="python value">
          15661
         </code>
         <code class="python value">
          2942
         </code>
        </div>
        <div class="line number11 index10 alt2">
         <code class="python value">
          16
         </code>
         <code class="python value">
          1055
         </code>
         <code class="python value">
          2191
         </code>
         <code class="python value">
          2119
         </code>
        </div>
        <div class="line number12 index11 alt1">
         <code class="python value">
          17
         </code>
         <code class="python value">
          5437
         </code>
         <code class="python value">
          6461
         </code>
         <code class="python value">
          734
         </code>
        </div>
        <div class="line number13 index12 alt2">
         <code class="python value">
          18
         </code>
         <code class="python value">
          1029
         </code>
         <code class="python value">
          1183
         </code>
         <code class="python value">
          2302
         </code>
        </div>
        <div class="line number14 index13 alt1">
         <code class="python value">
          19
         </code>
         <code class="python value">
          23710
         </code>
         <code class="python value">
          12222
         </code>
         <code class="python value">
          2598
         </code>
        </div>
        <div class="line number15 index14 alt2">
         <code class="python value">
          20
         </code>
         <code class="python value">
          1091
         </code>
         <code class="python value">
          2343
         </code>
         <code class="python value">
          2654
         </code>
        </div>
        <p>
        </p>
       </blockquote>
       <p>
        上述命令相当于
        <code>
         df.ix[10:20, ['Abra', 'Apayao', 'Benguet']]
        </code>
        。
       </p>
       <p>
        为了舍弃数据中的列，这里是列1(Apayao)和列2(Benguet)，我们使用drop属性，如下：
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python keyword">
          print
         </code>
         <code class="python plain">
          df.drop(df.columns[[
         </code>
         <code class="python value">
          1
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          2
         </code>
         <code class="python plain">
          ]], axis
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          1
         </code>
         <code class="python plain">
          ).head()
         </code>
        </div>
        <div class="line number2 index1 alt1">
        </div>
        <div class="line number3 index2 alt2">
         <code class="python comments">
          # OUTPUT
         </code>
        </div>
        <div class="line number4 index3 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          Abra  Ifugao  Kalinga
         </code>
        </div>
        <div class="line number5 index4 alt2">
         <code class="python value">
          0
         </code>
         <code class="python value">
          1243
         </code>
         <code class="python value">
          3300
         </code>
         <code class="python value">
          10553
         </code>
        </div>
        <div class="line number6 index5 alt1">
         <code class="python value">
          1
         </code>
         <code class="python value">
          4158
         </code>
         <code class="python value">
          8063
         </code>
         <code class="python value">
          35257
         </code>
        </div>
        <div class="line number7 index6 alt2">
         <code class="python value">
          2
         </code>
         <code class="python value">
          1787
         </code>
         <code class="python value">
          1074
         </code>
         <code class="python value">
          4544
         </code>
        </div>
        <div class="line number8 index7 alt1">
         <code class="python value">
          3
         </code>
         <code class="python value">
          17152
         </code>
         <code class="python value">
          19607
         </code>
         <code class="python value">
          31687
         </code>
        </div>
        <div class="line number9 index8 alt2">
         <code class="python value">
          4
         </code>
         <code class="python value">
          1266
         </code>
         <code class="python value">
          3315
         </code>
         <code class="python value">
          8520
         </code>
        </div>
       </blockquote>
       <div class="line number9 index8 alt2">
       </div>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_39370">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
            </td>
            <td class="code">
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        <code>
        </code>
        <code>
         axis
        </code>
        参数告诉函数到底舍弃列还是行。如果
        <code>
         axis
        </code>
        等于0，那么就舍弃行。
       </p>
       <h3>
        统计描述
       </h3>
       <p>
        下一步就是通过
        <code>
         describe
        </code>
        属性，对数据的统计特性进行描述：
       </p>
       <div class="line number1 index0 alt2">
        <code class="python keyword">
         print
        </code>
        <code class="python plain">
         df.describe()
        </code>
       </div>
       <div class="line number2 index1 alt1">
       </div>
       <div class="line number3 index2 alt2">
        <code class="python comments">
         # OUTPUT
        </code>
       </div>
       <div class="line number4 index3 alt1">
        <code class="python spaces">
        </code>
        <code class="python plain">
         Abra        Apayao      Benguet        Ifugao       Kalinga
        </code>
       </div>
       <div class="line number5 index4 alt2">
        <code class="python plain">
         count
        </code>
        <code class="python value">
         79.000000
        </code>
        <code class="python value">
         79.000000
        </code>
        <code class="python value">
         79.000000
        </code>
        <code class="python value">
         79.000000
        </code>
        <code class="python value">
         79.000000
        </code>
       </div>
       <div class="line number6 index5 alt1">
        <code class="python plain">
         mean
        </code>
        <code class="python value">
         12874.379747
        </code>
        <code class="python value">
         16860.645570
        </code>
        <code class="python value">
         3237.392405
        </code>
        <code class="python value">
         12414.620253
        </code>
        <code class="python value">
         30446.417722
        </code>
       </div>
       <div class="line number7 index6 alt2">
        <code class="python plain">
         std
        </code>
        <code class="python value">
         16746.466945
        </code>
        <code class="python value">
         15448.153794
        </code>
        <code class="python value">
         1588.536429
        </code>
        <code class="python value">
         5034.282019
        </code>
        <code class="python value">
         22245.707692
        </code>
       </div>
       <div class="line number8 index7 alt1">
        <code class="python functions">
         min
        </code>
        <code class="python value">
         927.000000
        </code>
        <code class="python value">
         401.000000
        </code>
        <code class="python value">
         148.000000
        </code>
        <code class="python value">
         1074.000000
        </code>
        <code class="python value">
         2346.000000
        </code>
       </div>
       <div class="line number9 index8 alt2">
        <code class="python value">
         25
        </code>
        <code class="python keyword">
         %
        </code>
        <code class="python value">
         1524.000000
        </code>
        <code class="python value">
         3435.500000
        </code>
        <code class="python value">
         2328.000000
        </code>
        <code class="python value">
         8205.000000
        </code>
        <code class="python value">
         8601.500000
        </code>
       </div>
       <div class="line number10 index9 alt1">
        <code class="python value">
         50
        </code>
        <code class="python keyword">
         %
        </code>
        <code class="python value">
         5790.000000
        </code>
        <code class="python value">
         10588.000000
        </code>
        <code class="python value">
         3202.000000
        </code>
        <code class="python value">
         13044.000000
        </code>
        <code class="python value">
         24494.000000
        </code>
       </div>
       <div class="line number11 index10 alt2">
        <code class="python value">
         75
        </code>
        <code class="python keyword">
         %
        </code>
        <code class="python value">
         13330.500000
        </code>
        <code class="python value">
         33289.000000
        </code>
        <code class="python value">
         3918.500000
        </code>
        <code class="python value">
         16099.500000
        </code>
        <code class="python value">
         52510.500000
        </code>
       </div>
       <div class="line number12 index11 alt1">
        <code class="python functions">
         max
        </code>
        <code class="python value">
         60303.000000
        </code>
        <code class="python value">
         54625.000000
        </code>
        <code class="python value">
         8813.000000
        </code>
        <code class="python value">
         21031.000000
        </code>
        <code class="python value">
         68663.000000
        </code>
       </div>
       <p>
       </p>
       <h3>
        假设检验
       </h3>
       <p>
        Python有一个很好的统计推断包。那就是scipy里面的stats。ttest_1samp实现了单样本t检验。因此，如果我们想检验数据Abra列的稻谷产量均值，通过零假设，这里我们假定总体稻谷产量均值为15000，我们有：
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python keyword">
          from
         </code>
         <code class="python plain">
          scipy
         </code>
         <code class="python keyword">
          import
         </code>
         <code class="python plain">
          stats as ss
         </code>
        </div>
        <div class="line number2 index1 alt1">
        </div>
        <div class="line number3 index2 alt2">
         <code class="python comments">
          # Perform one sample t-test using 1500 as the true mean
         </code>
        </div>
        <div class="line number4 index3 alt1">
         <code class="python functions">
          print
         </code>
         <code class="python plain">
          ss.ttest_1samp(a
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          df.ix[:,
         </code>
         <code class="python string">
          'Abra'
         </code>
         <code class="python plain">
          ], popmean
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          15000
         </code>
         <code class="python plain">
          )
         </code>
        </div>
        <div class="line number5 index4 alt2">
        </div>
        <div class="line number6 index5 alt1">
         <code class="python comments">
          # OUTPUT
         </code>
        </div>
        <div class="line number7 index6 alt2">
         <code class="python plain">
          (
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python value">
          1.1281738488299586
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          0.26270472069109496
         </code>
         <code class="python plain">
          )
         </code>
        </div>
       </blockquote>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_100992">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
            </td>
            <td class="code">
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        返回下述值组成的元祖：
       </p>
       <ul>
        <li>
         t : 浮点或数组类型
         <br/>
         t统计量
        </li>
        <li>
         prob : 浮点或数组类型
         <br/>
         two-tailed p-value 双侧概率值
        </li>
       </ul>
       <p>
        通过上面的输出，看到p值是0.267远大于α等于0.05，因此没有充分的证据说平均稻谷产量不是150000。将这个检验应用到所有的变量，同样假设均值为15000，我们有：
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python keyword">
          print
         </code>
         <code class="python plain">
          ss.ttest_1samp(a
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          df, popmean
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          15000
         </code>
         <code class="python plain">
          )
         </code>
        </div>
        <div class="line number2 index1 alt1">
        </div>
        <div class="line number3 index2 alt2">
         <code class="python comments">
          # OUTPUT
         </code>
        </div>
        <div class="line number4 index3 alt1">
         <code class="python plain">
          (array([
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python value">
          1.12817385
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          1.07053437
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python value">
          65.81425599
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python value">
          4.564575
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          6.17156198
         </code>
         <code class="python plain">
          ]),
         </code>
        </div>
        <div class="line number5 index4 alt2">
         <code class="python spaces">
         </code>
         <code class="python plain">
          array([
         </code>
         <code class="python value">
          2.62704721e
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python value">
          01
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          2.87680340e
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python value">
          01
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          4.15643528e
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python value">
          70
         </code>
         <code class="python plain">
          ,
         </code>
        </div>
        <div class="line number6 index5 alt1">
         <code class="python spaces">
         </code>
         <code class="python value">
          1.83764399e
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python value">
          05
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          2.82461897e
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python value">
          08
         </code>
         <code class="python plain">
          ]))
         </code>
        </div>
       </blockquote>
       <p>
       </p>
       <p>
        第一个数组是t统计量，第二个数组则是相应的p值。
       </p>
       <h3>
        可视化
       </h3>
       <p>
        Python中有许多可视化模块，最流行的当属matpalotlib库。稍加提及，我们也可选择bokeh和seaborn模块。之前的博文中，我已经说明了matplotlib库中的盒须图模块功能。
       </p>
       <p>
        <img src="http://dataunion.org/wp-content/uploads/2015/06/6941baebgw1epzcsbms47j20hr0hk0uk.jpg"/>
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python comments">
          # Import the module for plotting
         </code>
        </div>
        <div class="line number2 index1 alt1">
         <code class="python keyword">
          import
         </code>
         <code class="python plain">
          matplotlib.pyplot as plt
         </code>
        </div>
        <div class="line number3 index2 alt2">
         <code class="python spaces">
         </code>
         <code class="python plain">
          plt.show(df.plot(kind
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python string">
          'box'
         </code>
         <code class="python plain">
          ))
         </code>
        </div>
       </blockquote>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_995645">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
            </td>
            <td class="code">
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        现在，我们可以用pandas模块中集成R的ggplot主题来美化图表。要使用
        <a href="http://docs.ggplot2.org/current/index.html" target="_blank">
         ggplot
        </a>
        ，我们只需要在上述代码中多加一行，
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python keyword">
          import
         </code>
         <code class="python plain">
          matplotlib.pyplot as plt
         </code>
        </div>
        <div class="line number2 index1 alt1">
         <code class="python plain">
          pd.options.display.mpl_style
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python string">
          'default'
         </code>
         <code class="python comments">
          # Sets the plotting display theme to ggplot2
         </code>
        </div>
        <div class="line number3 index2 alt2">
         <code class="python plain">
          df.plot(kind
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python string">
          'box'
         </code>
         <code class="python plain">
          )
         </code>
        </div>
       </blockquote>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_655511">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
            </td>
            <td class="code">
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        这样我们就得到如下图表：
       </p>
       <p>
        <img src="http://dataunion.org/wp-content/uploads/2015/06/6941baebgw1epzcsb7dx5j20hi0hedhe.jpg"/>
       </p>
       <p>
        比matplotlib.pyplot主题简洁太多。但是在本博文中，我更愿意引入seaborn模块，该模块是一个统计数据可视化库。因此我们有：
       </p>
       <p>
        <img src="http://dataunion.org/wp-content/uploads/2015/06/6941baebgw1epzcsatuw7j20fc0fajrz.jpg"/>
       </p>
       <div class="line number1 index0 alt2">
        <code class="python comments">
         # Import the seaborn library
        </code>
       </div>
       <div class="line number2 index1 alt1">
        <code class="python keyword">
         import
        </code>
        <code class="python plain">
         seaborn as sns
        </code>
       </div>
       <div class="line number3 index2 alt2">
        <code class="python spaces">
        </code>
        <code class="python comments">
         # Do the boxplot
        </code>
       </div>
       <div class="line number4 index3 alt1">
        <code class="python plain">
         plt.show(sns.boxplot(df, widths
        </code>
        <code class="python keyword">
         =
        </code>
        <code class="python value">
         0.5
        </code>
        <code class="python plain">
         , color
        </code>
        <code class="python keyword">
         =
        </code>
        <code class="python string">
         "pastel"
        </code>
        <code class="python plain">
         ))
        </code>
       </div>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_144134">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
            </td>
            <td class="code">
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        多性感的盒式图，继续往下看。
        <br/>
        <img src="http://dataunion.org/wp-content/uploads/2015/06/6941baebgw1epzcsaf9w9j20fk0fagmf.jpg"/>
       </p>
       <p>
        <code class="python plain">
         plt.show(sns.violinplot(df, widths
        </code>
        <code class="python keyword">
         =
        </code>
        <code class="python value">
         0.5
        </code>
        <code class="python plain">
         , color
        </code>
        <code class="python keyword">
         =
        </code>
        <code class="python string">
         "pastel"
        </code>
        <code class="python plain">
         ))
        </code>
       </p>
       <p>
       </p>
       <p>
        <img src="http://dataunion.org/wp-content/uploads/2015/06/6941baebgw1epzcsa9lalj20g60fvgmo.jpg"/>
       </p>
       <p>
        <code class="python plain">
         plt.show(sns.distplot(df.ix[:,
        </code>
        <code class="python value">
         2
        </code>
        <code class="python plain">
         ], rug
        </code>
        <code class="python keyword">
         =
        </code>
        <code class="python color1">
         True
        </code>
        <code class="python plain">
         , bins
        </code>
        <code class="python keyword">
         =
        </code>
        <code class="python value">
         15
        </code>
        <code class="python plain">
         ))
        </code>
       </p>
       <p>
        <img src="http://dataunion.org/wp-content/uploads/2015/06/6941baebgw1epzcs9mmfdj20hb0gut9n.jpg"/>
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python plain">
          with sns.axes_style(
         </code>
         <code class="python string">
          "white"
         </code>
         <code class="python plain">
          ):
         </code>
        </div>
        <div class="line number2 index1 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          plt.show(sns.jointplot(df.ix[:,
         </code>
         <code class="python value">
          1
         </code>
         <code class="python plain">
          ], df.ix[:,
         </code>
         <code class="python value">
          2
         </code>
         <code class="python plain">
          ], kind
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python string">
          "kde"
         </code>
         <code class="python plain">
          ))
         </code>
        </div>
       </blockquote>
       <p>
       </p>
       <div>
       </div>
       <p>
        <img src="http://dataunion.org/wp-content/uploads/2015/06/6941baebgw1epzcs96mw3j20g40geq41.jpg"/>
       </p>
       <p>
        <code class="python plain">
         plt.show(sns.lmplot(
        </code>
        <code class="python string">
         "Benguet"
        </code>
        <code class="python plain">
         ,
        </code>
        <code class="python string">
         "Ifugao"
        </code>
        <code class="python plain">
         , df))
        </code>
       </p>
       <p>
       </p>
       <h3>
        创建自定义函数
       </h3>
       <p>
        在Python中，我们使用def函数来实现一个自定义函数。例如，如果我们要定义一个两数相加的函数，如下即可：
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python keyword">
          def
         </code>
         <code class="python plain">
          add_2int(x, y):
         </code>
        </div>
        <div class="line number2 index1 alt1">
         <code class="python spaces">
         </code>
         <code class="python keyword">
          return
         </code>
         <code class="python plain">
          x
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python plain">
          y
         </code>
        </div>
        <div class="line number3 index2 alt2">
        </div>
        <div class="line number4 index3 alt1">
         <code class="python functions">
          print
         </code>
         <code class="python plain">
          add_2int(
         </code>
         <code class="python value">
          2
         </code>
         <code class="python plain">
          ,
         </code>
         <code class="python value">
          2
         </code>
         <code class="python plain">
          )
         </code>
        </div>
        <div class="line number5 index4 alt2">
        </div>
        <div class="line number6 index5 alt1">
         <code class="python comments">
          # OUTPUT
         </code>
        </div>
        <div class="line number7 index6 alt2">
         <code class="python value">
          4
         </code>
        </div>
       </blockquote>
       <p>
       </p>
       <div>
        <div class="syntaxhighlighter notranslate python" id="highlighter_658374">
         <table border="0" cellpadding="0" cellspacing="0">
          <tbody>
           <tr>
            <td class="gutter">
            </td>
            <td class="code">
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <p>
        顺便说一下，Python中的缩进是很重要的。通过缩进来定义函数作用域，就像在R语言中使用大括号{…}一样。这有一个我们之前博文的例子：
       </p>
       <p>
        <a class="qa-blog-zoom" href="http://dataunion.org/wp-content/uploads/2015/06/QQ截图20150612185840.png">
         <img src="http://dataunion.org/wp-content/uploads/2015/06/QQ截图20150612185840.png"/>
        </a>
       </p>
       <p>
        Python中，程序如下：
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python keyword">
          import
         </code>
         <code class="python plain">
          numpy as np
         </code>
        </div>
        <div class="line number2 index1 alt1">
         <code class="python keyword">
          import
         </code>
         <code class="python plain">
          scipy.stats as ss
         </code>
        </div>
        <div class="line number3 index2 alt2">
        </div>
        <div class="line number4 index3 alt1">
         <code class="python keyword">
          def
         </code>
         <code class="python plain">
          case(n
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          10
         </code>
         <code class="python plain">
          , mu
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          3
         </code>
         <code class="python plain">
          , sigma
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          np.sqrt(
         </code>
         <code class="python value">
          5
         </code>
         <code class="python plain">
          ), p
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          0.025
         </code>
         <code class="python plain">
          , rep
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          100
         </code>
         <code class="python plain">
          ):
         </code>
        </div>
        <div class="line number5 index4 alt2">
         <code class="python spaces">
         </code>
         <code class="python plain">
          m
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          np.zeros((rep,
         </code>
         <code class="python value">
          4
         </code>
         <code class="python plain">
          ))
         </code>
        </div>
        <div class="line number6 index5 alt1">
        </div>
        <div class="line number7 index6 alt2">
         <code class="python spaces">
         </code>
         <code class="python keyword">
          for
         </code>
         <code class="python plain">
          i
         </code>
         <code class="python keyword">
          in
         </code>
         <code class="python functions">
          range
         </code>
         <code class="python plain">
          (rep):
         </code>
        </div>
        <div class="line number8 index7 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          norm
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          np.random.normal(loc
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          mu, scale
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          sigma, size
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          n)
         </code>
        </div>
        <div class="line number9 index8 alt2">
         <code class="python spaces">
         </code>
         <code class="python plain">
          xbar
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          np.mean(norm)
         </code>
        </div>
        <div class="line number10 index9 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          low
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          xbar
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python plain">
          ss.norm.ppf(q
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          1
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python plain">
          p)
         </code>
         <code class="python keyword">
          *
         </code>
         <code class="python plain">
          (sigma
         </code>
         <code class="python keyword">
          /
         </code>
         <code class="python plain">
          np.sqrt(n))
         </code>
        </div>
        <div class="line number11 index10 alt2">
         <code class="python spaces">
         </code>
         <code class="python plain">
          up
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          xbar
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python plain">
          ss.norm.ppf(q
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          1
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python plain">
          p)
         </code>
         <code class="python keyword">
          *
         </code>
         <code class="python plain">
          (sigma
         </code>
         <code class="python keyword">
          /
         </code>
         <code class="python plain">
          np.sqrt(n))
         </code>
        </div>
        <div class="line number12 index11 alt1">
        </div>
        <div class="line number13 index12 alt2">
         <code class="python spaces">
         </code>
         <code class="python keyword">
          if
         </code>
         <code class="python plain">
          (mu &gt; low) &amp; (mu &lt; up):
         </code>
        </div>
        <div class="line number14 index13 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          rem
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          1
         </code>
        </div>
        <div class="line number15 index14 alt2">
         <code class="python spaces">
         </code>
         <code class="python keyword">
          else
         </code>
         <code class="python plain">
          :
         </code>
        </div>
        <div class="line number16 index15 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          rem
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          0
         </code>
        </div>
        <div class="line number17 index16 alt2">
        </div>
        <div class="line number18 index17 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          m[i, :]
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          [xbar, low, up, rem]
         </code>
        </div>
        <div class="line number19 index18 alt2">
        </div>
        <div class="line number20 index19 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          inside
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          np.
         </code>
         <code class="python functions">
          sum
         </code>
         <code class="python plain">
          (m[:,
         </code>
         <code class="python value">
          3
         </code>
         <code class="python plain">
          ])
         </code>
        </div>
        <div class="line number21 index20 alt2">
         <code class="python spaces">
         </code>
         <code class="python plain">
          per
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          inside
         </code>
         <code class="python keyword">
          /
         </code>
         <code class="python plain">
          rep
         </code>
        </div>
        <div class="line number22 index21 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          desc
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python string">
          "There are "
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python functions">
          str
         </code>
         <code class="python plain">
          (inside)
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python string">
          " confidence intervals that contain "
         </code>
        </div>
        <div class="line number23 index22 alt2">
         <code class="python spaces">
         </code>
         <code class="python string">
          "the true mean ("
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python functions">
          str
         </code>
         <code class="python plain">
          (mu)
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python string">
          "), that is "
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python functions">
          str
         </code>
         <code class="python plain">
          (per)
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python string">
          " percent of the total CIs"
         </code>
        </div>
        <div class="line number24 index23 alt1">
        </div>
        <div class="line number25 index24 alt2">
         <code class="python spaces">
         </code>
         <code class="python keyword">
          return
         </code>
         <code class="python plain">
          {
         </code>
         <code class="python string">
          "Matrix"
         </code>
         <code class="python plain">
          : m,
         </code>
         <code class="python string">
          "Decision"
         </code>
         <code class="python plain">
          : desc}
         </code>
        </div>
       </blockquote>
       <p>
       </p>
       <p>
        上述代码读起来很简单，但是循环的时候就很慢了。下面针对上述代码进行了改进，这多亏了 Python专家，看我上篇博文的
        <a href="http://alstatr.blogspot.com/2014/01/python-and-r-is-python-really-faster.html#disqus_thread" target="_blank">
         15条意见
        </a>
        吧。
       </p>
       <blockquote>
        <div class="line number1 index0 alt2">
         <code class="python keyword">
          import
         </code>
         <code class="python plain">
          numpy as np
         </code>
        </div>
        <div class="line number2 index1 alt1">
         <code class="python keyword">
          import
         </code>
         <code class="python plain">
          scipy.stats as ss
         </code>
        </div>
        <div class="line number3 index2 alt2">
        </div>
        <div class="line number4 index3 alt1">
         <code class="python keyword">
          def
         </code>
         <code class="python plain">
          case2(n
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          10
         </code>
         <code class="python plain">
          , mu
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          3
         </code>
         <code class="python plain">
          , sigma
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          np.sqrt(
         </code>
         <code class="python value">
          5
         </code>
         <code class="python plain">
          ), p
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          0.025
         </code>
         <code class="python plain">
          , rep
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          100
         </code>
         <code class="python plain">
          ):
         </code>
        </div>
        <div class="line number5 index4 alt2">
         <code class="python spaces">
         </code>
         <code class="python plain">
          scaled_crit
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          ss.norm.ppf(q
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python value">
          1
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python plain">
          p)
         </code>
         <code class="python keyword">
          *
         </code>
         <code class="python plain">
          (sigma
         </code>
         <code class="python keyword">
          /
         </code>
         <code class="python plain">
          np.sqrt(n))
         </code>
        </div>
        <div class="line number6 index5 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          norm
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          np.random.normal(loc
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          mu, scale
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          sigma, size
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          (rep, n))
         </code>
        </div>
        <div class="line number7 index6 alt2">
        </div>
        <div class="line number8 index7 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          xbar
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          norm.mean(
         </code>
         <code class="python value">
          1
         </code>
         <code class="python plain">
          )
         </code>
        </div>
        <div class="line number9 index8 alt2">
         <code class="python spaces">
         </code>
         <code class="python plain">
          low
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          xbar
         </code>
         <code class="python keyword">
          -
         </code>
         <code class="python plain">
          scaled_crit
         </code>
        </div>
        <div class="line number10 index9 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          up
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          xbar
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python plain">
          scaled_crit
         </code>
        </div>
        <div class="line number11 index10 alt2">
        </div>
        <div class="line number12 index11 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          rem
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          (mu &gt; low) &amp; (mu &lt; up)
         </code>
        </div>
        <div class="line number13 index12 alt2">
         <code class="python spaces">
         </code>
         <code class="python plain">
          m
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          np.c_[xbar, low, up, rem]
         </code>
        </div>
        <div class="line number14 index13 alt1">
        </div>
        <div class="line number15 index14 alt2">
         <code class="python spaces">
         </code>
         <code class="python plain">
          inside
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          np.
         </code>
         <code class="python functions">
          sum
         </code>
         <code class="python plain">
          (m[:,
         </code>
         <code class="python value">
          3
         </code>
         <code class="python plain">
          ])
         </code>
        </div>
        <div class="line number16 index15 alt1">
         <code class="python spaces">
         </code>
         <code class="python plain">
          per
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python plain">
          inside
         </code>
         <code class="python keyword">
          /
         </code>
         <code class="python plain">
          rep
         </code>
        </div>
        <div class="line number17 index16 alt2">
         <code class="python spaces">
         </code>
         <code class="python plain">
          desc
         </code>
         <code class="python keyword">
          =
         </code>
         <code class="python string">
          "There are "
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python functions">
          str
         </code>
         <code class="python plain">
          (inside)
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python string">
          " confidence intervals that contain "
         </code>
        </div>
        <div class="line number18 index17 alt1">
         <code class="python spaces">
         </code>
         <code class="python string">
          "the true mean ("
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python functions">
          str
         </code>
         <code class="python plain">
          (mu)
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python string">
          "), that is "
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python functions">
          str
         </code>
         <code class="python plain">
          (per)
         </code>
         <code class="python keyword">
          +
         </code>
         <code class="python string">
          " percent of the total CIs"
         </code>
        </div>
        <div class="line number19 index18 alt2">
         <code class="python spaces">
         </code>
         <code class="python keyword">
          return
         </code>
         <code class="python plain">
          {
         </code>
         <code class="python string">
          "Matrix"
         </code>
         <code class="python plain">
          : m,
         </code>
         <code class="python string">
          "Decision"
         </code>
         <code class="python plain">
          : desc}
         </code>
        </div>
       </blockquote>
       <h3>
        更新
       </h3>
       <p>
        那些对于本文ipython notebook版本感兴趣的，请点击
        <a href="http://nuttenscl.be/Python_Getting_Started_with_Data_Analysis.html" target="_blank">
         这里
        </a>
        。这篇文章由
        <a href="https://twitter.com/NuttensC" target="_blank">
         Nuttens Claude
        </a>
        负责转换成 ipython notebook 。
       </p>
       <p>
       </p>
       <p>
        <a href="http://www.jobbole.com/members/dengcy">
         Den
        </a>
        翻译，英文出处：
        <a href="http://alstatr.blogspot.ca/2015/02/python-getting-started-with-data.html" target="_blank">
         alstatr.blogspot.ca
        </a>
       </p>
      </div>
      <div>
       <strong>
        注：转载文章均来自于公开网络，仅供学习使用，不会用于任何商业用途，如果侵犯到原作者的权益，请您与我们联系删除或者授权事宜，联系邮箱：contact@dataunion.org。转载数盟网站文章请注明原文章作者，否则产生的任何版权纠纷与数盟无关。
       </strong>
      </div>
      <!--content_text-->
      <div class="fenxian">
       <!-- JiaThis Button BEGIN -->
       <div class="jiathis_style_32x32">
        <p class="jiathis_button_weixin">
        </p>
        <p class="jiathis_button_tsina">
        </p>
        <p class="jiathis_button_qzone">
        </p>
        <p class="jiathis_button_cqq">
        </p>
        <p class="jiathis_button_tumblr">
        </p>
        <a class="jiathis jiathis_txt jtico jtico_jiathis" href="http://www.jiathis.com/share" target="_blank">
        </a>
        <p class="jiathis_counter_style">
        </p>
       </div>
       <!-- JiaThis Button END -->
      </div>
     </article>
     <!--content-->
     <!--相关文章-->
     <div class="xianguan">
      <div class="xianguantitle">
       相关文章！
      </div>
      <ul class="pic">
       <li>
        <a href="http://dataunion.org/20824.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/t018630756a7e263b33-300x165.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20824.html" rel="bookmark" title="如何判断一笔交易是否属于欺诈？你只是需要一点数据挖掘">
         如何判断一笔交易是否属于欺诈？你只是需要一点数据挖掘
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20820.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/1-300x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20820.html" rel="bookmark" title="人们对Python在企业级开发中的10大误解">
         人们对Python在企业级开发中的10大误解
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20811.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/t0133fcacae8523307b_副本-300x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20811.html" rel="bookmark" title="大神亲传：26条深度学习的金科玉律！">
         大神亲传：26条深度学习的金科玉律！
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20808.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/640.webp-11-300x137.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20808.html" rel="bookmark" title="我们是如何在一张地图上表现86万个数据的">
         我们是如何在一张地图上表现86万个数据的
        </a>
       </li>
      </ul>
     </div>
     <!--相关文章-->
     <div class="comment" id="comments">
      <!-- You can start editing here. -->
      <!-- If comments are open, but there are no comments. -->
      <div class="title">
       期待你一针见血的评论，Come on！
      </div>
      <div id="respond">
       <p>
        不用想啦，马上
        <a href="http://dataunion.org/wp-login.php?redirect_to=http%3A%2F%2Fdataunion.org%2F19488.html">
         "登录"
        </a>
        发表自已的想法.
       </p>
      </div>
     </div>
     <!-- .nav-single -->
    </div>
    <!--Container End-->
    <aside id="sitebar">
     <div class="sitebar_list2">
      <div class="wptag">
       <span class="tagtitle">
        热门标签+
       </span>
       <div class="tagg">
        <ul class="menu" id="menu-%e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1605" id="menu-item-1605">
          <a href="http://taidizh.com/">
           泰迪智慧
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20884" id="menu-item-20884">
          <a href="http://www.transwarp.cn/">
           星环科技
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3538" id="menu-item-3538">
          <a href="http://datall.org/">
           珈和遥感
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20888" id="menu-item-20888">
          <a href="http://www.chinahadoop.cn/">
           小象学院
          </a>
         </li>
        </ul>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <div class="textwidget">
       <div align="center">
        <a href="http://study.163.com/course/courseMain.htm?courseId=991022" target="_blank">
         <img src="http://dataunion.org/wp-content/uploads/2016/03/dv.jpg"/>
        </a>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       文章分类
      </h4>
      <div class="tagcloud">
       <a class="tag-link-44" href="http://dataunion.org/category/industry/demo" style="font-size: 10.204724409449pt;" title="4个话题">
        Demo展示
       </a>
       <a class="tag-link-31" href="http://dataunion.org/category/experts" style="font-size: 15.826771653543pt;" title="52个话题">
        专家团队
       </a>
       <a class="tag-link-870" href="http://dataunion.org/category/tech/ai" style="font-size: 19.795275590551pt;" title="273个话题">
        人工智能
       </a>
       <a class="tag-link-488" href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f" style="font-size: 8pt;" title="1个话题">
        加入数盟
       </a>
       <a class="tag-link-869" href="http://dataunion.org/category/tech/viz" style="font-size: 17.204724409449pt;" title="93个话题">
        可视化
       </a>
       <a class="tag-link-30" href="http://dataunion.org/category/partners" style="font-size: 10.645669291339pt;" title="5个话题">
        合作伙伴
       </a>
       <a class="tag-link-889" href="http://dataunion.org/category/parterc" style="font-size: 11.582677165354pt;" title="8个话题">
        合作会议
       </a>
       <a class="tag-link-104" href="http://dataunion.org/category/books" style="font-size: 12.96062992126pt;" title="15个话题">
        图书
       </a>
       <a class="tag-link-220" href="http://dataunion.org/category/tech/base" style="font-size: 19.850393700787pt;" title="281个话题">
        基础架构
       </a>
       <a class="tag-link-219" href="http://dataunion.org/category/tech/analysis" style="font-size: 19.409448818898pt;" title="232个话题">
        数据分析
       </a>
       <a class="tag-link-887" href="http://dataunion.org/category/tech/dm" style="font-size: 13.291338582677pt;" title="17个话题">
        数据挖掘
       </a>
       <a class="tag-link-34" href="http://dataunion.org/category/tech" style="font-size: 20.732283464567pt;" title="404个话题">
        文章
       </a>
       <a class="tag-link-1" href="http://dataunion.org/category/uncategorized" style="font-size: 22pt;" title="693个话题">
        未分类
       </a>
       <a class="tag-link-4" href="http://dataunion.org/category/events" style="font-size: 14.503937007874pt;" title="29个话题">
        活动
       </a>
       <a class="tag-link-890" href="http://dataunion.org/category/tech/%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0" style="font-size: 10.204724409449pt;" title="4个话题">
        深度学习
       </a>
       <a class="tag-link-221" href="http://dataunion.org/category/tech/devl" style="font-size: 18.968503937008pt;" title="193个话题">
        编程语言
       </a>
       <a class="tag-link-888" href="http://dataunion.org/category/career" style="font-size: 15.661417322835pt;" title="48个话题">
        职业规划
       </a>
       <a class="tag-link-5" href="http://dataunion.org/category/jobs" style="font-size: 14.11811023622pt;" title="25个话题">
        职位
       </a>
       <a class="tag-link-871" href="http://dataunion.org/category/industry" style="font-size: 15.716535433071pt;" title="49个话题">
        行业
       </a>
       <a class="tag-link-613" href="http://dataunion.org/category/industry/case" style="font-size: 16.984251968504pt;" title="84个话题">
        行业应用
       </a>
       <a class="tag-link-885" href="http://dataunion.org/category/industry/news" style="font-size: 17.425196850394pt;" title="102个话题">
        行业资讯
       </a>
       <a class="tag-link-10" href="http://dataunion.org/category/training" style="font-size: 14.228346456693pt;" title="26个话题">
        课程
       </a>
       <a class="tag-link-16" href="http://dataunion.org/category/sources" style="font-size: 15.661417322835pt;" title="48个话题">
        资源
       </a>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       功能
      </h4>
      <ul>
       <li>
        <a href="http://dataunion.org/wp-login.php?action=register">
         注册
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/wp-login.php">
         登录
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/feed">
         文章
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/comments/feed">
         评论
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="https://cn.wordpress.org/" title="基于WordPress，一个优美、先进的个人信息发布平台。">
         WordPress.org
        </a>
       </li>
      </ul>
     </div>
    </aside>
    <div class="clear">
    </div>
   </div>
   <!--main-->
   ﻿
   <footer id="dibu">
    <div class="about">
     <div class="right">
      <ul class="menu" id="menu-%e5%ba%95%e9%83%a8%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-18024" id="menu-item-18024">
        <a href="http://dataunion.org/category/partners">
         合作伙伴
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20881" id="menu-item-20881">
        <a href="http://dataunion.org/contribute">
         文章投稿
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20872" id="menu-item-20872">
        <a href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f">
         加入数盟
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22441" id="menu-item-22441">
        <a href="http://dataunion.org/f-links">
         友情链接
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20874" id="menu-item-20874">
        <a href="http://dataunion.org/aboutus">
         关于数盟
        </a>
       </li>
      </ul>
      <p class="banquan">
       数盟社区        ，
        做最棒的数据科学社区
      </p>
     </div>
     <div class="left">
      <ul class="bottomlist">
       <li>
        <a href="http://weibo.com/DataScientistUnion  " target="_blank" 　title="">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weibo.png"/>
        </a>
       </li>
       <li>
        <a class="cd-popup-trigger" href="http://dataunion.org/19488.html#0">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weixin.png"/>
        </a>
       </li>
      </ul>
      <div class="cd-popup">
       <div class="cd-popup-container">
        <h1>
         扫描二维码,加微信公众号
        </h1>
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/2014-12-06-1515289049.png"/>
        <a class="cd-popup-close" href="http://dataunion.org/19488.html">
        </a>
       </div>
       <!-- cd-popup-container -->
      </div>
      <!-- cd-popup -->
     </div>
    </div>
    <!--about-->
    <div class="bottom">
     <a href="http://dataunion.org/">
      数盟社区
     </a>
     <a href="http://www.miitbeian.gov.cn/" rel="external nofollow" target="_blank">
      京ICP备14026740号
     </a>
     联系我们：
     <a href="mailto:contact@dataunion.org" target="_blank">
      contact@dataunion.org
     </a>
     <div class="tongji">
     </div>
     <!--bottom-->
     <div class="scroll" id="scroll" style="display:none;">
      ︿
     </div>
    </div>
   </footer>
   <!--dibu-->
  </div>
 </body>
</html>